/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2019年3月17日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package test.lesson3.sort;

import java.util.Arrays;

/**
 * @Type ShellSort
 * @Desc
 * @author 52489
 * @date 2019年3月17日
 * @Version V1.0
 */
public class ShellSort {
    public static void sort(int[] nums) {
        for (int i = nums.length / 2; i > 0; i /= 2) {
            for (int j = 0; j < nums.length; j = j + i) {
                int stard = nums[j + i - 1];
                for (int k = 0; k < j + 1; k = k + i) {
                    int x = j - k;
                    if (x != 0) {
                        x = x - 1;
                    }
                    if (nums[x] > stard) {
                        int tmp = nums[x + i];
                        nums[x + i] = nums[x];
                        nums[x] = tmp;
                    } else {
                        continue;
                    }
                }
                System.out.print(Arrays.toString(nums) + "\n");

            }
            System.out.print(Arrays.toString(nums) + "\n");

        }
    }

    public static void main(String[] args) {
        int nums[] = { 2, 1, 4, 6, 4, 7, 8, 5, 10, 11 };
        sort(nums);
        System.out.println(Arrays.toString(nums));
    }
}
